//
//  CategoryTableViewController.m
//  GaoBiaoB
//
//  Created by lanou3g on 16/1/18.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "CategoryTableViewController.h"
//#import "HomeCatrgeryModel.h"
#import "Nuomishuo.h"
#import "TuandanFenglei.h"
#import "TuanSmallModel.h"
#import "HomePageDataManager.h"
#import "HomePageTableViewController.h"
#import "CategoryDeTailTableViewController.h"
@interface CategoryTableViewController ()

//接收数组
@property(nonatomic,strong)NSArray *dataArray;
//懒加载初始化数据数组
@property(nonatomic,strong)NSMutableArray *subArray;


@end
NSString *categoryLGJ = @"category";
@implementation CategoryTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    self.dataArray = [NSArray arrayWithArray:self.subArray];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:categoryLGJ];
    [HomePageDataManager sharedHomeDataManger].block= ^(){
        [self.tableView reloadData];
    };
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:categoryLGJ forIndexPath:indexPath];
    TuanSmallModel *small = _dataArray[indexPath.row];
    cell.textLabel.text = small.subcat_name;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *array = [NSArray arrayWithArray:[HomePageDataManager sharedHomeDataManger].categoryIDArray];
    NSString * smallID = array[indexPath.row];
    
    //点击进入详细分类界面
    CategoryDeTailTableViewController *detail = [[CategoryDeTailTableViewController alloc]initWithStyle:UITableViewStyleGrouped];
    
    //=========把二级分类id传出去
    detail.sub_category_ID = smallID;
    detail.oneCityID = _category_City;
    detail.twoCityID = _category_SubCity;
    
    [self presentViewController:detail animated:YES completion:^{
    }];
}
-(NSMutableArray *)subArray{
    if (_subArray == nil) {
        _subArray = [NSMutableArray array];
        HomePageDataManager *maneger = [HomePageDataManager sharedHomeDataManger];
        NSArray *array = [NSArray arrayWithArray:maneger.categoryNameArray];
        NSString *str = [NSString stringWithFormat:@"%@",array[_category_ID]];
        NSDictionary *dict = [NSDictionary dictionaryWithDictionary:maneger.categoryDict];
        _subArray = dict[[NSString stringWithFormat:@"%@",str]];
    }
    return _subArray;
}

@end
